#include <iostream>
#include <algorithm>
using namespace std;

int myMin(int a,int b) {
	return a<b?a:b;
}
int main() {
	int n,a;
	cin>>n>>a;
	int *data = new int[n];

	int min,max;
	for(int i=0; i<n; i++)
		cin>>data[i];

	sort(data,data+n);
	min = data[0];
	max = data[n-1];

	if(a < min)
		cout<<data[n-2] - a;
	else if( a > max)
		cout<<a - data[1];
	else {
		if(n<=3) {
			if(n == 2){
				cout<<((a - data[0])> (data[1] - a)? (data[1] - a):(a - data[0]));
			}
			else
			{
				if(a > data[1])
				    cout<<myMin(a - data[0],data[2] - data[1] + (a- data[1] > data[2] -a? data[2] -a:a - data[1]));
				else
				    cout<<myMin(data[2] - a,data[1]- data[0] + (a - data[0] > data[1]-a?data[1]-a:a-data[0]));
			}
		} else {
			int d1,d2,d3,d4;
			if(a<data[n-1] && n > data[n-2]) {
				d1 = a - data[0];
				d2 = (a - data[n-1])*2 + (a - data[1]);
				cout<<myMin(d1,d2);
			} else if(a >= data[1] && a <= data[n-2]) {
				d1 = (data[n-1] - a)*2 +  (a - data[1]);
				d2 = (data[n-2] - a)*2 + (a - data[0]);
				d3 = (a - data[1])*2 + (data[n-1] - a);
				d4 = (a - data[0])*2 + (data[n-2] - a);
				cout<<myMin(d4,myMin(d3,myMin(d1,d2)));
			} else {
				d1 = data[n-1] - a;
				d2 = (a - data[0])*2 + (data[n-1] - a);
				cout<<myMin(d1,d2);
			}
		}
	}

	return 0;
}
